<?php
namespace app\home\controller;
use app\admin\model\Filess;
use app\admin\model\News;
use app\admin\model\Newstype;
use app\admin\model\Text;
use app\admin\model\Video;
use app\home\model\Apply;
use app\home\model\Slideshow;
use think\Session;
use app\home\model\Teacher;
class  Indexs extends Base
{
    public function index($tid = "null"){
        $this->teacher_session($tid);
        //轮播图
        $slide =Slideshow::where(["status"=>1])->order("sort desc")->select();
        //热卖新闻7条
        $news = News::order("sorttype asc")->limit(7)->select();
        foreach($news as $k => $v){
            $type = Newstype::where(array("id"=>$v['newstype']))->find();
            $news[$k]['tt'] = mb_substr($type['type_name'],0,1,"utf-8");
        }
        $teacher_tel = Session::has("teacher_n") ?  Session::get("teacher_n")['tel'] : $this->getAllSetting()['gf_tel'];
        //查询热门推荐信息
        $rmtj = Text::where(array("k"=>'rmtj'))->find();
        $data = array(
            "setting" => $this->getAllSetting(),
            "slide" => $slide,
            "news"=>$news,
            "rmtj"=>$rmtj['val'],
            "tid" => $tid,
            "teacher_tel"=>$teacher_tel
        );
        return view("index",$data);
    }

    public function video(){
        $user = $this->user_info();
        //查询当前用户的报名信息
        $Applys =  Apply::where(array('idcard'=>$user['idcard']))->select();
        $videos = array();
        foreach($Applys as $v){
           $video = Video::where(array("type"=>$v['courseid']))->select();

            $videos = array_merge($videos,collection($video)->toArray());

        }
        //查询热门推荐信息
        $data = array(
            "setting" => $this->getAllSetting(),
            "video" => $videos,
        );
        return view("video",$data);
    }
    public function files(){
        $user = $this->user_info();
        //查询当前用户的报名信息
        $Applys =  Apply::where(array('idcard'=>$user['idcard']))->select();
        $Filess = array();
        foreach($Applys as $v){
            $file = Filess::where(array("type"=>$v['courseid']))->select();

            $Filess = array_merge($Filess,collection($file)->toArray());

        }
        //查询热门推荐信息
        $data = array(
            "setting" => $this->getAllSetting(),
            "Filess" => $Filess,
        );
        return view("files",$data);
    }
}
